grammar NewsRequest;

options {
language=Java;
}
@header {
package com.dynamicalsoftware.news.parser;
import java.io.PrintWriter;
}
@lexer::header {
package com.dynamicalsoftware.news.parser;
}
@members {
public PrintWriter writer = null;
}

ask	:
	(
	repository
	|
	topic
	|
	interests
	|
	format
	|
	count
	)+
	;
repository	:
	'repository:' STRING
	{ writer.write("<tr><td>repository</td><td>" + $STRING.text + "</td></tr>"); }
	;
topic	:
	'topic:' STRING
	{ writer.write("<tr><td>topic to cover</td><td>" + $STRING.text + "</td></tr>"); }
	;
interests	:
	interest ( ',' STRING
	{ writer.write("<tr><td>area of interest</td><td>" + $STRING.text + "</td></tr>"); }	 
	 )*
	;
interest	:
	'interest:' STRING
	{ writer.write("<tr><td>area of interest</td><td>" + $STRING.text + "</td></tr>"); }
	;
format	:
	'format:' STRING
	{ writer.write("<tr><td>format of response</td><td>" + $STRING.text + "</td></tr>"); }
	;
count	:
	'count:' INT
	{ writer.write("<tr><td>max number of items to return</td><td>" + $INT.text + "</td></tr>"); }
	;
INT :	'0'..'9'+
    ;

WS  :   ( ' '
        | '\t'
        | '\r'
        | '\n'
        )+ {$channel=HIDDEN;}
    ;

STRING
    :  '"' ( ESC_SEQ | ~('\\'|'"') )* '"'
    ;

fragment
HEX_DIGIT : ('0'..'9'|'a'..'f'|'A'..'F') ;

fragment
ESC_SEQ
    :   '\\' ('b'|'t'|'n'|'f'|'r'|'\"'|'\''|'\\')
    |   UNICODE_ESC
    |   OCTAL_ESC
    ;

fragment
OCTAL_ESC
    :   '\\' ('0'..'3') ('0'..'7') ('0'..'7')
    |   '\\' ('0'..'7') ('0'..'7')
    |   '\\' ('0'..'7')
    ;

fragment
UNICODE_ESC
    :   '\\' 'u' HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT
    ;
